//
//  PushSetViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/22.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "PushSetViewController.h"
#import "RentVieitor.h"

@interface PushSetViewController ()

@end

@implementation PushSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"推送设置";
    self.view.backgroundColor = BackgroundColor;
    [self creatLeftView];
    [self creatView];
}

- (void)creatLeftView {
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 10,15 );
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(0, 0, 20, 17);
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"消息"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(noticeAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

- (void)creatView {
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, KWidth-40, 13)];
    label.text = @"为确保不错过房源动态,请打开接受通知开关";
    label.textColor = [Utils colorConvertFromString:@"#999999"];
    label.font = [UIFont systemFontOfSize:13];
    label.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:label];
    NSArray *titleArray = @[@"接受新消息通知",@"声音",@"震动",@"房源成交",@"点评消息"];
    //选项视图
    CGFloat heigt = 50;
    for (int i=0; i<titleArray.count; i++) {
        
        UIView *selectView = [[UIView alloc] init];
        selectView.backgroundColor = [UIColor whiteColor];
        selectView.tag = 100+i;
        if (i == 0 ) {
            
            selectView.frame = CGRectMake(0,10+heigt*i , KWidth, heigt);
            
        }else if (i>0 &i<3) {
            
            selectView.frame = CGRectMake(0, heigt*i+50, KWidth, heigt);
        }
        else {
            
            selectView.frame = CGRectMake(0, heigt*i+60, KWidth, heigt);
        }
        [self.view addSubview:selectView];
        
        
        UILabel *selectLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, KWidth/2, 30)];
        selectLabel.text = titleArray[i];
        selectLabel.font = [UIFont systemFontOfSize:15];
        selectLabel.textAlignment = NSTextAlignmentLeft;
        selectLabel.textColor = [Utils colorConvertFromString:@"#101010"];
        [selectView addSubview:selectLabel];
        
        UISwitch *switchView = [[UISwitch alloc] initWithFrame:CGRectMake(KWidth-70.f,10.f, 120.f, 30.f)];
        switchView.on = YES;//设置初始为ON的一边
        switchView.tag = 100+i;
        [switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];   // 开关事件切换通知
        [selectView addSubview:switchView];
        
        
                //分割线
                CALayer *MlineLayer5 = [CALayer layer];
                MlineLayer5.backgroundColor = [[Utils colorConvertFromString:@"#F2F2F2"] CGColor];
                if (i == 1 || i== 3 ) {
                    MlineLayer5.frame = CGRectMake(20 ,heigt-1, KWidth,1);
                }
                [selectView.layer addSublayer:MlineLayer5];
    }

}

-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
    
        if (switchButton.tag == 100) {
           
            //接受新消息通知
            
            
        }else if(switchButton.tag == 101) {
            
            //声音
            
        }else if(switchButton.tag == 102) {
            
            //震动
            
        }else if(switchButton.tag == 103) {
            
            //房源成交
            
        }else if(switchButton.tag == 104) {
            
            //点评消息
            
        }
        
    }else {
       
        if (switchButton.tag == 100) {
            
        }else if(switchButton.tag == 101) {
            
        }else if(switchButton.tag == 102) {
            
        }else if(switchButton.tag == 103) {
            
        }else if(switchButton.tag == 104) {
            
        }
        
    }
}



- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)noticeAction {
    
}

@end
